package inherit;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2022-05-14
 * Time:13:33
 */
class Animal{
    public String name;
    public int age;

    static {
        System.out.println("Animal的静态代码块");
    }

    {
        System.out.println("Animal的实例代码块");
    }

    public Animal(){
        System.out.println("Animal不带参数的构造方法!");
    }

    public Animal(String name,int age){
        this.age=age;
        this.name=name;
    }


    public void eat(){
        System.out.println(name+"正在吃饭!");
    }
}

class  Dog extends Animal{
    public float weight;

    static {
        System.out.println("Dog的静态代码块");
    }

    {
        System.out.println("Dog的实例代码块");
    }

    public Dog() {
        System.out.println("Dog不带参数的构造方法!");
    }
    public Dog(String name,int age,float weight){
        super(name, age);
        this.weight=weight;
    }

    public void bark(){
        System.out.println(name+"正在汪汪汪!");
    }
}

class Cat extends Animal{

    public Cat(String name, int age) {

    }

    public void bark(){
        System.out.println(name+"正在喵喵喵!");
    }
}


public class Test {
    public static void main(String[] args) {
        Dog dog = new Dog();
    }


    /*public static void main1(String[] args) {
        *//*Dog dog = new Dog();
// dog类中并没有定义任何成员变量，name和age属性肯定是从父类Animal中继承下来的
        System.out.println(dog.name);
        System.out.println(dog.age);
// dog访问的eat()和bark()方法也是从Animal中继承下来的
        dog.eat();
        dog.bark();*//*
        Dog dog = new Dog();
    }*/
}

